package net.oschina.bilbodai.common.beanutil.bean;

import net.oschina.bilbodai.common.beanutil.bean.annotation.DumpIgnore;
import net.oschina.bilbodai.common.beanutil.bean.annotation.DumpProperty;
import net.oschina.bilbodai.common.beanutil.property.PropertyUtil;

import java.util.Date;
import java.util.List;

/**
 * @author daimao  Date: 16/4/20 Time: 下午6:06
 * @version $Id$
 */
public class DumpBeanSample implements IBeanAccessor {

    @Override
    public Object propertyDump(Object src, Object target) {
        Foo srcFoo = (Foo) src;
        FooTarget targetFoo = (FooTarget) target;

        if (targetFoo.getName() == null)
            targetFoo.setName(srcFoo.getName());
        if (targetFoo.getDesc() == null)
            targetFoo.setDesc(srcFoo.getDesc());

        targetFoo.setAge((Integer) PropertyUtil.getProperty("age", srcFoo));
        return target;
    }

    @Override
    public Object propertyDump(Object src) {
        return null;
    }

    public static class FooBody {
        private int[] bits;

        public int[] getBits() {
            return bits;
        }

        public void setBits(int[] bits) {
            this.bits = bits;
        }
    }

    public static class Foo {
        private String name;
        private String desc;
        private int age;

        private Date date;
        private boolean done;

        private FooBody body;

        private List<Foo> fooList;

        public List<Foo> getFooList() {
            return fooList;
        }

        public void setFooList(List<Foo> fooList) {
            this.fooList = fooList;
        }

        public FooBody getBody() {
            return body;
        }

        public void setBody(FooBody body) {
            this.body = body;
        }

        //        @PropertyDump(name = "time")
        public Date getDate() {
            return date;
        }

        public void setDate(Date date) {
            this.date = date;
        }

        public boolean isDone() {
            return done;
        }

        public void setDone(boolean done) {
            this.done = done;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    public static class FooTarget {
        private String name;
        private String desc;
        private int age;
        @DumpIgnore
        private boolean done;
        @DumpProperty(name = "date")
        private Date time;
        @DumpProperty(name = "body",attrPath = "bits[0]", attrType = Integer.class)
        private Integer bit;
        @DumpIgnore
        private List<FooTarget> fooTargets;

        public List<FooTarget> getFooTargets() {
            return fooTargets;
        }

        public void setFooTargets(List<FooTarget> fooTargets) {
            this.fooTargets = fooTargets;
        }

        public Integer getBit() {
            return bit;
        }

        public void setBit(Integer bit) {
            this.bit = bit;
        }

        public boolean isDone() {
            return done;
        }

        public void setDone(boolean done) {
            this.done = done;
        }

        public Date getTime() {
            return time;
        }

        public void setTime(Date time) {
            this.time = time;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}